<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('HBase集群列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
           <!-- <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>tag：</label>
                                <input type="text" name="tagName"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>-->

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="hbase:cluster:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="hbase:cluster:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('hbase:cluster:edit')}]];
        var removeFlag = [[${@permission.hasPermi('hbase:cluster:remove')}]];
        var prefix = ctx + "system/cluster";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "HBaseCluster",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'clusterId',
                    title: '集群ID'
                },
                {
                    field: 'clusterName',
                    title: '集群名称'
                },
                 {
                    field: 'clusterVersion',
                    title: '集群版本'
                },
                {
                    field: 'clusterDesc',
                    title: '集群描述'
                },
                {
                    field: 'clusterConfig',
                    title: '集群配置',
                    visible: false
                },
                {
                    field: 'state',
                    title: '集群状态',
                    align: "center",
                    formatter: function (value, row, index) {
                        return showHBaseClusterState(row);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.clusterId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="copyClusterInfo(\'' + row.id + '\')"><i class="fa fa-edit"></i>复制</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        /**集群状态显示*/
        function showHBaseClusterState(row) {
            console.log(row);
             if (row.state === 'offline') {
                 return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="onlineCluster(\'' + row.id + '\')"></i>';
             } else {
                 return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="offlineCluster(\'' + row.id + '\')"></i>';
             }
        }

        /* 集群上下线状态管理-下线 */
        function offlineCluster(clusterId) {
            $.modal.confirm("确认要下线集群吗？", function () {
                $.operate.post(prefix + "/offlineCluster", {"id": clusterId, "state": 'offline'}, function (res) {
                    $.modal.msg(res.msg)
                });
            })
        }

        /* 集群上下线状态管理-上线 */
        function onlineCluster(clusterId) {
            $.modal.confirm("确认要上线集群吗？", function () {
                $.operate.post(prefix + "/onlineCluster", {"id": clusterId, "state": 'online'}, function (res) {
                    $.modal.msg(res.msg)
                });
            })
        }

        function copyClusterInfo(clusterId) {
            $.modal.confirm("确认要复制一条集群信息？", function () {
                $.operate.post(prefix + "/copyClusterInfo", {"id": clusterId, "state": ''}, function (res) {
                    $.modal.msg(res.msg)
                });
            })
        }
    </script>
</body>
</html>